#include <iostream>
#include <string>
#include <fstream>

#include "bundle.h"

int main(int argc,char* argv[])
{
    if(argc != 3)
    {
        std::cout << "uncompress [压缩文件名] [解压文件名]" << std::endl;
        return -1;
    }

    std::string ifilename = argv[1];
    std::string ofilename = argv[2];


    //打开要解压缩的文件，将其读到body里
    std::ifstream ifs;
    ifs.open(ifilename,std::ios::binary);

    ifs.seekg(0,std::ios::end);
    int fsize = ifs.tellg();
    ifs.seekg(0,std::ios::beg);

    std::string body;
    body.resize(fsize);

    ifs.read(&body[0],fsize); 

    //对body进行解压缩
    std::string unpacked = bundle::unpack(body);


    //将解压缩串写入文件
    std::ofstream ofs;
    ofs.open(ofilename);

    ofs.write(&unpacked[0],unpacked.size()); 


    //关闭文件
    ifs.close();
    ofs.close();

    return 0;
}